package logic

import (
	"context"

	"laundry-service/app/client/internal/svc"
	"laundry-service/app/client/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CategorylistLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCategorylistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CategorylistLogic {
	return &CategorylistLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CategorylistLogic) Categorylist(req *types.Request) (resp *types.CategorylistReply, err error) {

	data, err := l.svcCtx.Db.GetCategoryList()
	if err != nil {
		return nil, err
	}
	rsp := new(types.CategorylistReply)
	result := make([]*types.Category, 0)
	for _, v := range data {
		res := new(types.Category)
		res.ID = v.ID
		res.Name = v.Name
		res.Remark = v.Remark
		result = append(result, res)
	}
	rsp.Data = result
	return rsp, nil
}
